package org.jackysoft.interceptor;

import java.lang.reflect.Method;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.jackysoft.annotations.ActionRequestMethod;
import org.jackysoft.annotations.MethodInceptor;
import org.springframework.web.servlet.ModelAndView;

@MethodInceptor(method = { ActionRequestMethod.list,
		ActionRequestMethod.select, ActionRequestMethod.pager })
public class PagerInterceptor extends AbstractInterceptor {

	@Override
	public void postHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler,
			ModelAndView modelAndView) throws Exception {

		int page = (int) modelAndView.getModelMap().get("page");
		int rows = (int) modelAndView.getModelMap().get("rows");

		// 获得这个action中所对应的class类型参数
		Method getsPage_Method = service.getClass().getMethod("pager",int.class, int.class);
		// 调用service的插入bean方法

		Object pageBean = getsPage_Method.invoke(service, page, rows);

		modelAndView.addObject("pager", pageBean);

	}
}
